package models

import (
	"gorm.io/gorm"
)

type House struct {
	gorm.Model
	UserId int64   `gorm:"type:int(3);comment:'用户ID'"`
	Title  string  `gorm:"type:varchar(50);comment:'房源名称'"`
	Ads    string  `gorm:"type:varchar(255);comment:'房源地址'"`
	Square string  `gorm:"type:varchar(20);comment:'面积'"`
	Floor  string  `gorm:"type:varchar(20);comment:'房源楼层'"`
	Price  float64 `gorm:"type:decimal(10,2);comment:'房源价格'"`
	Status int64   `gorm:"type:int(3);comment:'房源状态'；default:1;comment:'1 正常、2 下架'"`
}

type HouseInfo struct {
	gorm.Model
	Image     string `gorm:"type:varchar(255);comment:'房源图片'"`
	PriceInfo string `gorm:"type:varchar(20);comment:'价格走势'"`
	Around    string `gorm:"type:varchar(20);comment:'周边配套'"`
	HouseId   int    `gorm:"type:int(3);comment:'房源ID'"`
}

func (h *HouseInfo) GetHouseInfoById() error {
	return DB.Where("house_id=?", h.HouseId).Limit(1).Find(&h).Error
}

func (h *House) GetHouseById() error {
	return DB.Where("id=?", h.ID).Limit(1).Find(&h).Error
}

func (h *House) GetHouseByUserId() error {
	return DB.Where("user_id=?", h.UserId).Limit(1).Find(&h).Error
}

func (h *House) CreateHouse() error {
	return DB.Create(&h).Error
}

func (h *House) UpdateHouse() error {
	return DB.Updates(&h).Error
}
